package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.PermissionDao;
import com.itheima.dao.RoleDao;
import com.itheima.dao.UserDao;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

@Transactional
@Service(interfaceClass = UserService.class)
public class UserServiceImp implements UserService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private RoleDao roleDao;
    @Autowired
    private PermissionDao permissionDao;
    //根据用户名查询数据库获取用户信息和关联的角色信息,同时需要查询角色关联的权限信息
    @Override
    public User findByUsername(String username) {
        User user = userDao.findByUsername(username);//查询用户基本信息,不包含用户的信息
//        if(user==null){
//            return null;
//        }
//        //根据用户id查询对应的角色
//        Integer userId = user.getId();
//        Set<Role> roles = roleDao.findByUserId(userId);
//        for (Role role : roles) {
//            //根据角色id查找对应的权限
//            Integer roleId = role.getId();
//            Set<Permission> permissions = permissionDao.findByRoleId(roleId);
//            role.setPermissions(permissions);
//        }
//        user.setRoles(roles);
        return user;
    }
}
